package com.huixue.cn.ztej.api.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huixue.cn.ztej.bean.Results;
import com.huixue.cn.ztej.bean.TGoods;
import com.huixue.cn.ztej.controller.BaseController;
import com.huixue.cn.ztej.service.TGoodsService;
import com.huixue.cn.ztej.utils.SystemContents.API_RETURN_STATUS;


@Controller
public class ApiTGoodsController extends BaseController {

	@Autowired(required = true)
	private TGoodsService tGoodsService;
	
	@RequestMapping(value = "/api/goods/list/{type}/{subjectId}")
	@ResponseBody
	public Results list(@PathVariable("type")Integer type,@PathVariable("subjectId")Integer subjectId,
			HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object> searchParams = new HashMap<String,Object>();
		if(type!=null && type>0){
			searchParams.put("goodType", String.valueOf(type));
		}
		
		if(subjectId!=null && subjectId>0){
			searchParams.put("subjectId", String.valueOf(subjectId));
		}
		
		List<TGoods> list = tGoodsService.list(searchParams);
		
		Results results = new Results(
				API_RETURN_STATUS.NORMAL.value(),
				API_RETURN_STATUS.NORMAL.desc(),
				list
				);
		return results;
	}
}
